import { pinyin } from 'pinyin-pro'

addEventListener(
  'message',
  ({
    data: { data, inputList, ouputList, input }
  }: {
    data: {
      data: string[]
      inputList: string[]
      ouputList: string[]
      input: string
    }
  }) => {
    postMessage(
      data.filter(
        (e) =>
          e !== input &&
          !ouputList.includes(e) &&
          !inputList.includes(e) &&
          (e.startsWith([...input].at(-1) ?? '') ||
            pinyin(e, { toneType: 'none', type: 'array' })[0] ===
              pinyin(input, { toneType: 'none', type: 'array' }).at(-1))
      )
    )
  }
)
